<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <style>
            a{color:#333; text-decoration:none;}
            a:hover{ color:#900; text-decoration:underline;}
            table{width:100%; border: 0;}
            td a{ display:block; margin:1px; padding:1px; border:1px solid #069; text-decoration:none; color:#333; text-align:center;}
            td a:hover{ color:#FFF; background-color:#09C;}
            .default{width:78px; min-height:12px; height:auto; border:1px dashed #CCC; background-color:#fcfcfc; color:#333; padding:3px; margin:3px 0px;}
            .selection{width:78px; min-height:12px; height:auto; border:1px dashed #CCC; background-color:#09F; color:#FFF; padding:3px; margin:3px 0px;}
        </style>
        <script src="jq6.js"></script>
        <script>
            $(document).ready(function(){    
                //初始化
                $("#tab1").show();
                $("#tab2").hide();
        
                var d = new Date();
                setCalendar(d);

                var url = localStorage.gateURL;
                var t = d.getFullYear() + '-' + (d.getMonth()+1) + '-' + d.getDate();
                var u = localStorage.svnUsername;
                var p = localStorage.svnPassword;
                var c = localStorage.svnURL;
        
                $("#last").click(function(){
                    AddMonths(d,-1);
                    setCalendar(d);
                });
        
                $("#next").click(function(){
                    AddMonths(d,1);
                    setCalendar(d);
                });
        
                $("#fresh").click(function(){
                    d = new Date();
                    setCalendar(d);
                    $("#tab1").show();
                    $("#tab2").hide();
                });
        
                //var notification = webkitNotifications.createNotification('ico.gif','提醒您:','亲!该吃药了~');
                //notification.show();
                //setTimeout(function(){notification.cancel();},2000);
        
                //生成日历表格
                function setCalendar(d){ 
                    f = getMonFirstDay(2012,d.getMonth());
                    l = GetMonthDayCount(d);
                    i = 0;
                    s = '<tr>';
                    for(x=0;x<f;x++){
                        s = s + '<td> </td>';
                        i++;
                    }
                    for(x=1;x<=l;x++){
                        if(i%7==0){
                            s = s + '</tr><tr>';
                        }
                        s = s + '<td><a href="###">'+x+'</a></td>';                   
                        i++;
                    }
                    s = s + '</tr>';
                    $('#d').html(s);
                    D = d.getFullYear() + '-' + GetFullMonth(d);
                    $('#n').html(D);
                
                    $("tr a").click(function(){
                        var t = D+'-'+$(this).html();
                        getlogs(t);
                        excel = url+'svnExcel.php?t='+t+'&u='+u+'&c='+c+'&p='+p;
                        $("#excel").attr('href',excel);
                    });       
                }
                
                //获取SVN日志
                function getlogs(t){
                    $("#tab1").hide();
                    $("#tab2").show();
                    $("#tab2 table").html('数据加载中...');
                    var str = "<tr><th width='120'>工作内容</th><th width='30'>时长</th></tr>";
                    $.getJSON(url+"svnlog.php?callback=?",{t:t,u:u,p:p,c:c},function(data){
                        if(data.length>=1){
                            $.each(data,function(k,v){
                                str = str + "<tr><td>"+v[1]+"</td><td>"+v[2]+"</td></tr>";
                                str = str + "<tr><td colspan='2'><hr /></td></tr>"
                            });
                            $("#tab2 table").html(str);
                            $("#tab2").show(); 
                        }else{
                            var notification = webkitNotifications.createNotification('ico.gif','提醒您:','数据获取失败了~');
                            notification.show();
                            setTimeout(function(){notification.cancel();},2000);
                        }
                    });
                }
            });
    
            function AddMonths(date,value){  
                date.setMonth(date.getMonth()+value);  
            }
    
            function IsToday(date){  
                return IsDateEquals(date,new Date());  
            }
    
            //返回某个日期对应的月份的天数  
            function GetMonthDayCount(date){  
                switch(date.getMonth()+1){  
                    case 1:
                    case 3:
                    case 5:
                    case 7:
                    case 8:
                    case 10:
                    case 12:  
                        return 31;  
                    case 4:
                    case 6:
                    case 9:
                    case 11:  
                        return 30;  
                }
                date=new Date(date);  
                var lastd=28;  
                date.setDate(29);  
                while(date.getMonth()==1){
                    lastd++;  
                    AddDays(date,1);  
                }
                return lastd;
            }
    
            //返回某年某月第一天是星期几
            function getMonFirstDay(year,mon){
                date = new Date();
                date.setFullYear(year, mon, 1);
                return date.getUTCDay();
            }
            // 返回月份（修正为两位数） 
            function GetFullMonth(date) 
            { 
                var v=date.getMonth()+1; 
                if(v>9)return v.toString(); 
                return "0"+v; 
            } 
        </script>
    </head>
    <body onload="" style="width:160px; font-size:12px;">
        <div id="tab1">
            <div align="center"><a href="###" id="last">上月</a> | <span id="n"></span> | <a href="###" id="next">下月</a></div>
            <table>
                <tr><th>日</th><th>一</th><th>二</th><th>三</th><th>四</th><th>五</th><th>六</th></tr>
            </table>
            <table id="d"></table>
        </div>
        <div id="tab2">
            <table></table>
            <div>[<a href="###" id="excel" target="_blank">预览Excel</a>] [<a href="###">发送邮件</a>]</div>
        </div>
        <hr />
        [<a id="fresh" href="javascript:void(0)">今日</a>] [<a href="options.html" target="_blank">选项</a>]
        <div>by zuojianghua</div>
    </body>
</html>